// ==UserScript==
// @name DIO-TOOLS-David1327
// @name:fr DIO-TOOLS-David1327
// @namespace https://www.tuto-de-david1327.com/pages/info/dio-tools-david1327.html
// @version 4.33
// @author DIONY (changes and bug fixes by David1327)
// @description Version 2023. DIO-Tools + Quack is a small extension for the browser game Grepolis. (counter, displays, smilies, trade options, changes to the layout)
// @description:FR Version 2023. DIO-Tools + Quack est une petite extension du jeu par navigateur Grepolis. (compteur, affichages, smileys, options commerciales, modifications de la mise en page)
// @match https://*.grepolis.com/game/*
// @match https://*.forum.grepolis.com/*
// @match https://dio-david1327.github.io/*
// @updateURL https://dio-david1327.github.io/DIO-TOOLS-David1327/code.user.js
// @downloadURL https://dio-david1327.github.io/DIO-TOOLS-David1327/code.user.js
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js
// @resource clipboard https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js
// @icon https://dio-david1327.github.io/img/smileys/bussi2.gif
// @icon64 https://www.tuto-de-david1327.com/medias/images/dio-tools-david1327.jpg
// @copyright 2013+, DIONY and 2019+, David1327
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_deleteValue
// @grant GM_xmlhttpRequest
// @grant GM_getResourceText
// @license GPL-3.0-only
// ==/UserScript==
let dio_version = GM.info.script.version;
/*******************************************************************************************************************************
* Global stuff
*******************************************************************************************************************************/
let uw = unsafeWindow || window, $ = uw.jQuery, DATA, GMM, url_dev;
// GM-API?
if (GM.info.scriptHandler == "Greasemonkey") GMM = false
else GMM = (typeof GM_info === 'object');
//GMM = true;
//GMM = false;
//url_dev = true;
console.log('%c|= ' + GM.info.script.name + ' is active v' + dio_version + ' (' + GM.info.scriptHandler + ' v' + GM.info.version + ') [GMM ' + GMM + '] =|', 'color: green; font-size: 1em; font-weight: bolder; ');
function loadValue(name, default_val) {
var value;
if (GMM) { value = GM_getValue(name, default_val); }
else { value = localStorage.getItem(name) || default_val; }
if (typeof (value) === "string") { value = JSON.parse(value) }
return value;
}
// LOAD DATA
if ((uw.location.pathname.indexOf("game") >= 0)) {
var WID = uw.Game.world_id, MID = uw.Game.market_id, AID = uw.Game.alliance_id;
DATA = {
// GLOBAL
options: loadValue("options", "{}"),
test: loadValue("test", "{}"),
user: loadValue("dio_user", "{}"),
notification: loadValue('notif', '0'),
update: loadValue('update', '0'),
notiff: loadValue('notiff', '0'),
error: loadValue('error', '{}'),
// WORLD
townTypes: loadValue(WID + "_townTypes", "{}"),
townAuto: loadValue(WID + "_townAuto", "{}"),
sentUnits: loadValue(WID + "_sentUnits", '{ "attack": {}, "support": {} }'),
biremes: loadValue(WID + "_biremes", "{}"), //old
bullseyeUnit: loadValue(WID + "_bullseyeUnit", '{ "current_group" : -1 }'), // new
worldWonder: loadValue(WID + "_wonder", '{ "ratio": {}, "storage": {}, "map": {} }'),
Overviews: loadValue("Overviews", '{ "Buildings": "", "Culture": "", "Gods": "" }'),
// MARKET
worldWonderTypes: loadValue(MID + "_wonderTypes", '{}')
};
if (!DATA.worldWonder.map) { DATA.worldWonder.map = {}; }
// Temporary:
if (typeof DATA.options.dio_trd == 'boolean') { DATA.options.dio_per = DATA.options.dio_rec = DATA.options.dio_trd; delete DATA.options.dio_trd; }
if (typeof DATA.options.dio_mov == 'boolean') { DATA.options.dio_act = DATA.options.dio_mov; delete DATA.options.dio_mov; }
if (typeof DATA.options.dio_twn == 'boolean') { DATA.options.dio_tic = DATA.options.dio_til = DATA.options.dio_tim = DATA.options.dio_twn; delete DATA.options.dio_twn; }
if (GMM) GM_deleteValue("notification");
}
// GM: EXPORT FUNCTIONS
uw.saveValueGM = function (name, val) { setTimeout(() => { GM_setValue(name, val); }, 0); };
uw.deleteValueGM = function (name) { setTimeout(() => { GM_deleteValue(name); }, 0); };
var time_a, time_b;
// APPEND SCRIPT
function appendScript() {
//console.log("GM-API: " + gm_bool);
if (document.getElementsByTagName('body')[0]) {
if (GMM) {
const scriptclipboard = document.createElement("script");
scriptclipboard.textContent = GM_getResourceText("clipboard");
document.body.appendChild(scriptclipboard);
}
var dioscript = document.createElement('script');
dioscript.type = 'text/javascript';
dioscript.id = 'diotools';
time_a = uw.Timestamp.client();
dioscript.textContent = DIO_GAME.toString().replace(/uw\./g, "") + "\n DIO_GAME('" + dio_version + "', " + GMM + ", '" + JSON.stringify(DATA).replace(/'/g, "##") + "', " + time_a + ", " + url_dev + ");";
document.body.appendChild(dioscript);
} else setTimeout(() => { appendScript(); }, 500);
}
if (location.host === "dio-david1327.github.io") { DIO_PAGE(); } // PAGE
else if ((uw.location.pathname.indexOf("game") >= 0)) {
try {
$('').appendTo("head");
if (!GMM) $('').appendTo("head");
//$('').appendTo("head");
} catch (error) { console.log(error, '').appendTo("head");
*/
console.debug("SPRACHE", MID);
// Translation GET
function getTexts(category, name, data) {
var txt = "???", lang = MID;
if (DATA.test.lang && !data) { lang = DATA.test.lang }
if (LANG[lang]) {
if (LANG[lang][category]) {
if (LANG[lang][category][name]) { txt = LANG[lang][category][name]; }
else {
if (LANG.en[category]) {
if (LANG.AUTO[category][name]) { txt = LANG.AUTO[category][name]; }
else if (LANG.en[category][name]) { txt = LANG.en[category][name]; }
}
}
} else {
if (LANG.en[category]) {
if (LANG.AUTO[category][name]) { txt = LANG.AUTO[category][name]; }
else if (LANG.en[category][name]) { txt = LANG.en[category][name]; }
}
}
} else {
if (LANG.en[category]) {
if (LANG.AUTO[category][name]) { txt = LANG.AUTO[category][name]; }
else if (LANG.en[category][name]) { txt = LANG.en[category][name]; }
}
}
return txt;
}
/*******************************************************************************************************************************
* Settings
*******************************************************************************************************************************/
// (De)activation of the features
var Options_def = {
dio_bir: true, // Biremes counter
dio_ava: true, // Available units
dio_ava2: true, // Available units
dio_sml: true, // Smileys
dio_str: true, // Unit strength
dio_tra: true, // Transport capacity
dio_per: true, // Percentual Trade
dio_rec: true, // Recruiting Trade
dio_way: true, // Troop speed
dio_cnt: true, // Attack/support counter
dio_sim: true, // Simulator
dio_act: true, // Activity boxes
dio_tsk: true, // Task bar
dio_pop: true, // Favor popup
dio_bbc: true, // BBCode bar
dio_com: true, // Unit comparison
dio_TEST: false,// Unit comparison
dio_tic: true, // Town icons
dio_tic2: true, // Town icons
dio_til: true, // Town icons: Town list
dio_tim: true, // Town icons: Map
dio_tiw: true, // Town Popup
dio_tpt: true, // Town Popup troop
dio_tis: true, // Town Popup support
dio_tih: true, // Town Popup Hero
dio_tir: true, // Town Popup Resource
dio_wwc: true, // World wonder counter
dio_wwr: false, // World wonder ranking
dio_wwi: false, // World wonder icons
dio_con: true, // Context menu
dio_sen: true, // Sent units
dio_tov: false, // Town overview
dio_scr: true, // Mausrad,
dio_Scr: true, // Scrollbar Style
dio_Tow: true, // town bb
dio_Rew: true, // minimize Daily Reward
dio_Fdm: true, // ForumDeleteMultiple
dio_Sel: true, // selectunitshelper
dio_Cul: true, // cultureOverview
dio_Cup: true, // cultureProgress
dio_Cuo: true, // culturePoints
dio_Hot: true, // hotkeys
dio_Isl: true, // islandFarmingVillages
dio_Ish: true, // farmingvillageshelper
dio_Hio: true, // hidesOverview
dio_Hid: true, // hidesIndexIron
dio_Tol: true, // townslist
dio_Cib: true, // city_view_btn
dio_Ciw: false, // city_view_window
dio_Cic: false, // city_btn_construction
dio_Tti: true, // townTradeImprovement
dio_Mse: true, // MessageExport
dio_Rep: true, // reports
dio_Rct: true, // resCounter
dio_BBt: true, // BBtowninfo
dio_Rtt: false, // removeTooltipps
dio_Buc: true, // buildingControl
dio_Cuc: true, // cultureControl
dio_err: false, // Error Reports
dio_her: true, // Thrakische Eroberung
//color
dio_aaa: true,
dio_bbb: false,
dio_ccc: false,
dio_ddd: false,
dio_eee: false,
dio_tro: false,
};
if (!uw.Game.features.end_game_type == "end_game_type_world_wonder") {
delete Options_def.dio_wwc;
delete Options_def.dio_wwr;
delete Options_def.dio_wwi;
}
if (!typeof (uw.MoleHoleOnBoard) == "undefined") {
delete Options_def.dio_Ciw;
}
if (!typeof (uw.FLASK_GAME) == "undefined") {
delete Options_def.dio_til;
delete Options_def.dio_Sel;
}
if (uw.location.pathname.indexOf("game") >= 0) {
for (var opt in Options_def) {
if (Options_def.hasOwnProperty(opt)) { if (DATA.options[opt] === undefined) { DATA.options[opt] = Options_def[opt]; } }
}
}
var version_text = '', version_color = 'black';
$('').appendTo("head");
function getLatestVersion() {
var version_latest = "??";
try { version_latest = uw.dio_latest_version; } catch (error) { errorHandling(error, "dio_latest_version (getLatestVersion)"); }
var v_info = $('#dio_version_info');
try {
if (version_text === '') {
if (dio_version > version_latest) {
version_text = "" + getTexts("Settings", 'version_dev') + "
";
version_color = 'darkblue';
$('.dio_settings .dio_icon').css({ filter: "hue-rotate(100deg)" });
tooltip_settings();
} else if (dio_version == version_latest) {
version_text = "" + getTexts("Settings", 'version_new') + "
";
} else {
version_text = "" + getTexts("Settings", 'version_old') + "
" +
"--> " + getTexts("Settings", 'version_update') + "";
version_color = 'crimson';
$('.dio_settings .dio_icon').css({ filter: "hue-rotate(260deg)" });
tooltip_settings();
}
v_info.html(version_text).css({ color: version_color });
}
else { v_info.html(version_text).css({ color: version_color }); }
} catch (error) {
errorHandling(error, "getLatestVersion");
if (version_text === '') {
version_text = "" + getTexts("Settings", 'version_old') + "
" +
"--> " + getTexts("Settings", 'version_update') + "";
version_color = 'crimson';
$('.dio_settings .dio_icon').css({ filter: "hue-rotate(260deg)" });
v_info.html(version_text).css({ color: version_color });
}
else { v_info.html(version_text).css({ color: version_color }); }
}
}
/*******************************************************************************************************************************
* Add DIO-Tools to grepo settings
*******************************************************************************************************************************/
// Styles
$('').appendTo('head');
function settings() {
var wid = $(".settings-menu").get(0).parentNode.id;
if (!$("#dio_tools").get(0)) {
$(".settings-menu ul:last").append('
';
if (dio.lang() == "fr") HTML_tab2 += '
'; //scrolling="no"
else HTML_tab2 += '
'; //scrolling="no";
HTML_tab2 += '
' + getTexts("labels", "ingame_name")[0] + '
' +
'
' + getTexts("labels", "ingame_name")[1] + '
' +
'
' +
'' + getTexts("labels", "donat") + ' |
' +
(function () {
var donNb2 = -1, donations = [], donations2 = [], donations3 = [], donations4 = [], donation_table = "", donation_table2 = "", donation_table3 = "", donation_table4 = "";
$.each(donationsListe, function (a) {
donNb2++;
if (donNb2 < (don + (reste > 0 ? 1 : 0))) { donations.push(donationsListe[donNb2]) }
else if (donNb2 < (don + don + (reste > 1 ? 2 : reste))) { donations2.push(donationsListe[donNb2]) }
else if (donNb2 < (don + don + don + (reste > 2 ? 3 : reste))) { donations3.push(donationsListe[donNb2]) }
else { donations4.push(donationsListe[donNb2]) }
})
var d = 0;
for (d = 0; d < donations.length; d++) {
var donation_class = "";
switch (donations[d][0]) {
case 1: donation_class = "gold"; break;
case 2: donation_class = "silver"; break;
case 3: donation_class = "bronze"; break;
default: donation_class = "green2"; break;
}
donation_table += ' | ' + donations[d][4] + ' | ' + donations[d][2] + '€ |
';
}
for (d = 0; d < donations2.length; d++) { donation_table2 += ' | ' + donations2[d][4] + ' | ' + donations2[d][2] + '€ |
'; }
for (d = 0; d < donations3.length; d++) { donation_table3 += ' | ' + donations3[d][4] + ' | ' + donations3[d][2] + '€ |
'; }
for (d = 0; d < donations4.length; d++) { donation_table4 += ' | ' + donations4[d][4] + ' | ' + donations4[d][2] + '€ |
'; }
return donation_table + '
' + donation_table4;
})() +
'
' +
'
';
return HTML_tab2;
}
//Traductions
function tab3() {
var HTML_tab3 = "";
var supported_lang = [getTexts("translations", "info"), getTexts("translations", "add_lang")];
$.each(LANG, function (a, b) {
if (a != "AUTO") { supported_lang.push(a); }
});
HTML_tab3 += '' + dio.grepo_dropdown_flag("langdiv", supported_lang, null, null, null)[0].outerHTML + '
';
//var lngFlags = "";
HTML_tab3 += '' + getTexts("translations", "please_note") + ':' +
'
' +
'- ' + getTexts("translations", "trans_infotext1") + '
' +
''; // style="opacity:0.30;"
$.each(LANG, function (a) {
if (a != "AUTO") { HTML_tab3 += '

'; }
});
HTML_tab3 += '
' +
'- ' + getTexts("translations", "trans_infotext2") + '
' +
'
' +
'- ' + getTexts("translations", "trans_infotext3") +
'
- ' + getTexts("translations", "trans_infotext4") + '
' +
'' + dio.createButton(getTexts("translations", "send")) + '
' +
'- ' + getTexts("translations", "trans_infotext5") + '
' +
'- ' + getTexts("translations", "trans_infotext6") + '
' +
'' +
'
' + getTexts("Settings", "cat_forum") + '' +
'' +
'
' + getTexts("Settings", "forum") + '' +
'' +
'
Discord' +
'
' + getTexts("translations", "credits") + ':';
HTML_tab3 += '' +
(function () {
var translations = [
["DE", "Diony / Krieger des Lichts"],
["EN", "Diony"],
["IT", "amliam / Pyrux"],
["FR", "eclat49 / David1327"],
["RU", "MrBobr"],
["PL", "anpu"],
["ES", "Juana de Castilla"],
["BR", "HELL / BUGS"],
["CZ", "Piwus"],
["RO", "Nicolae01"],
["NL", "Firebloem / Analist434343"],
["GR", "AbstractGR"],
];
var translation_table = "";
for (var d = 0; d < translations.length; d++) {
translation_table += ' |  + '.png) | ' + translations[d][0] + ': | ' + translations[d][1] + ' |
';
}
return translation_table;
})() +
'
';
HTML_tab3 += '
';
//HTML_tab3 += dio.grepo_btn("diomenu_einstellungen_sendmail", getTexts("Settings", "send"))[0].outerHTML;
return HTML_tab3;
}
//BUG
function tab4() {
var HTML_tab4 = '' +
(script.grcrt ? 'Grcrt: true; ' : "") +
(script.HMole ? 'HMole: true; ' : "") +
(script.Gt ? 'Gt: true; ' : "") +
(script.FLASK ? 'FLASK: true; ' : "") +
(script.Quack ? 'Quack: true; ' : "") +
(script.GrepoData ? 'GrepoData: true; ' : "") + '
';
$.each(errordio, function (name) {
if (name !== "nb") {
name_a += '
Function: ' + errordio[name].function + '
' +
'Message: ' + errordio[name].message + '
' +
(typeof (errorr[name]) !== "undefined" ? ('Error: ' + errorr[name].error + '
') : "") +
'Version: ' + errordio[name].version + '
' +
'latest_version: ' + uw.MM.DIO.info_dio.latest_version + '
' +
'Browser: ' + errordio[name].browser + '
' +
'System: ' + errordio[name].system + '
' +
'Nb: ' + errordio[name].nb + '
' +
'Date: ' + errordio[name].date + '
' +
'Date fin: ' + errordio[name].date_fin + '
';
}
});
HTML_tab4 += name_a;
if (name_a === "") { HTML_tab4 += "no bug"; }
HTML_tab4 += '
';
return HTML_tab4;
}
function handle_and_style() {
dio.clipboard("#dio-copy-Traductions-quote", null, "handle_and_style", true)
$("#dioerrordio").click(() => {
var name_a = "", errordio = DATA.error[dio_version], script = uw.MM.DIO.info_dio.script, errorr = uw.MM.DIO.errorDio;
var name_b = '' +
'Grcrt: ' + (script.grcrt ? true : false) + "; " +
'HMole: ' + (script.HMole ? true : false) + "; " +
'Gt: ' + (script.Gt ? true : false) + "; " +
'FLASK: ' + (script.FLASK ? true : false) + "; " +
'Quack: ' + (script.Quack ? true : false) + "; " +
'GrepoData: ' + (script.GrepoData ? true : false);
$.each(errordio, function (name) {
if (name !== "nb") {
name_a += 'Function: ' + errordio[name].function + "\n" +
'Message: ' + errordio[name].message + "\n" +
(typeof (errorr[name]) !== "undefined" ? ('Error: ' + errorr[name].error + "\n") : "") +
'Version: ' + errordio[name].version + "\n" +
'latest_version ' + uw.MM.DIO.info_dio.latest_version + "\n" +
'Browser: ' + errordio[name].browser + "\n" +
'System: ' + errordio[name].system + "\n" +
'Nb: ' + errordio[name].nb + "\n" +
'Date: ' + errordio[name].date + "\n" +
'Date fin: ' + errordio[name].date_fin + "\n\n";
}
});
if (name_a === "") {
uw.HumanMessage.error(dio_icon + "no bug");
return;
}
uw.hOpenWindow.showConfirmDialog('', getTexts("translations", "send"), function () {
var trans_HTML_send = pName + '